<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户点击元素时弹出"Hello World"</title>
</head>

<body>
    <p>该实例使用 addEventListener() 方法在按钮中添加点击事件。 </p>
    <button id="myBtn">点我</button>
    <script>
        document.getElementById("myBtn").addEventListener("click", function () {
            alert("Hello World!");
        });
    </script>
</body>

</html>